package com.happy.sky.concurrent.thread2.lock;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo2 {
    public static void main(String[] args) throws InterruptedException {
        closeDoor();
    }

    private static void closeDoor() throws InterruptedException {
        //创建CountDownLatch,初始容量为10，模拟10名员工
        CountDownLatch countDownLatch=new CountDownLatch(10);
        for (int i=1;i<=10;i++){
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + "\t" + "忙完工作，下班。");
                //计数器减1
                countDownLatch.countDown();
            },EmpEnum.forEach(i).getName()).start();
        }
        //当计数器的值变为0,因调用await方法被阻塞的线程会被唤醒,继续执行
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t值班人员锁门离开公司");
    }
}
